
package com.xjnt.frameworks.core;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import com.jfinal.core.Controller;

public abstract class BaseController extends Controller {
	
	/**
	 * 转换实体集合为所有实体主键的数组
	 * @param lst
	 * @return
	 */
	protected Object[] toIds(List<? extends BaseModel<?>> lst){
		Object[] ids = new Object[lst.size()];
		for (int i = 0; i < lst.size(); i++) {
			BaseModel<?> model = lst.get(i);
			ids[i] = model.getStr("uuid");
		}
		return ids;
	}
	
	public BaseModel<?> getCurrUser(){
		Subject subject = SecurityUtils.getSubject();
		if(null == subject){
			return null;
		}
		Session session = subject.getSession(false);
		if(null == session){
			return null;
		}
		return (BaseModel<?>)session.getAttribute("CURR_USER");
	}
}
